<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 导入mapbox依赖 -->
    <script src='https://api.mapbox.com/mapbox-gl-js/v2.12.0/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.12.0/mapbox-gl.css' rel='stylesheet' />
    <style>
        * {
            margin: 0;
            padding: 0
        }

        #map {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>

<body>
    <!-- 2、设置地图容器的挂载点 -->
    <div id="map">

    </div>
    <script>
        const gaode = {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "type": "raster",
                    "tiles": ["http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}"],
                    "tileSize": 256
                }
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
                "minzoom": 0,
                "maxzoom": 22
            }]
        }
        /* 3、实例化地图 */
        mapboxgl.accessToken = 'pk.eyJ1IjoiY2hlbmdiZW5jaGFvIiwiYSI6ImNsODU3aGRiODA0Y2UzcHBzZmFlcmdqZ2sifQ.8k59W_pB_Riwe6o-MneRlA'
        const map = new mapboxgl.Map({
            container: "map",
            /* style-layers */
            style: 'mapbox://styles/mapbox/streets-v12',
            center: [114.40088809833583,
                30.4663210497187],
            zoom: 14
        })
        var data = 'http://39.103.151.139:8000/gis/zhongdi';
        map.on("style.load", () => {
            map.addSource("zhongdi-source", {
                type: "geojson",
                data
            })
            map.addLayer({
                id: "zhongdi-layer",
                source: "zhongdi-source",
                type: "fill-extrusion",
                paint: {
                    /* 可以获取geojson中properties属性中的值 */
                    'fill-extrusion-height': 100,
                    'fill-extrusion-color': "#ff2d51",
                    'fill-extrusion-opacity': 0.5,
                    /* 设置离地的高度 */
                }
            })
        })
        let timer = null;
        map.on("mousedown", () => {
            /* 鼠标按下的时候触发 */
            timer = setInterval(() => {
                var height = map.getPaintProperty("zhongdi-layer", 'fill-extrusion-height')
                height += 10;
                /* setPaintProperty(layer-name,paint-key,paint-value) */
                map.setPaintProperty("zhongdi-layer", 'fill-extrusion-height', height)
            }, 100)
        })
        map.on("mouseup", () => {
            /* 松开鼠标 */
            clearInterval(timer)
        })
    </script>
</body>

</html>